<template>
	<view class="card gray" style="position: relative;">
		<view style="display: flex;flex-direction: column;">
			<view style="display: flex;gap: 5px;align-items: center;padding: 5px 0;">
				<text>From:</text>
				<tn-avatar :url="sConf.pics + data.source.face" size="sm" shadow></tn-avatar>
				<view style="font-size: small;font-weight: bold;"> {{ data.source.nicename }}</view>
			</view>
			<view style="padding: 5px 0;font-size: large;font-weight: bolder;text-wrap: wrap;">
				{{ data.desc }}
			</view>
			<view style="font-size: smaller;display: flex;justify-content: flex-end;width: 100%;">
				<text>{{ data.created }}</text>
			</view>
		</view>
		<view style="padding: 5px;position: absolute;top: 0;right: 0;">
			<view v-if="data.status === 0" class="forest" @click="InviteChange(1)"
				style="font-size: smaller;display: flex;align-items: center;gap: 5px;padding: 5px 10px;border-radius: 5px;">
				<tn-icon name="success-circle" size="32"></tn-icon>
				<view class=""> 签收 </view>
			</view>
			<tn-icon v-if="data.status === 1" name="success-circle" size="64" color="#4cd964"></tn-icon>
		</view>
	</view>
</template>

<script>
	import utils from '@/common/utils';
	export default {
		name: "sub-message-sems",
		data() {
			return {
				sConf: getApp().globalData,
				test: 'abcde',
			};
		},
		props: {
			data: {
				type: Object,
				default: null
			}
		},
		methods: {
			/**
			 * 确认事件
			 * @param {Object} e
			 */
			InviteChange(e) {
				let that = this;
				// let scc = e === 1 ? '同意' : '拒绝';
				// uni.showModal({
				// 	title: scc,
				// 	content: '是否要 ' + scc + ' 这份邀请？不能撤销的哦。',
				// 	success(res) {
				// 		if (res.confirm) {
				// 			console.log('同意了');
				// 			that.patchInviteState(e);
				// 		}
				// 	}
				// })
				that.patchInviteState(1);
			},
			/**
			 * 应答状态
			 * @param {Object} e
			 */
			patchInviteState(e) {
				let host = this.sConf.host + '/weapps/mesList/' + this.data.id + '/';
				let token = this.sConf.token || ''
				let data = {
					status: e
				}
				utils.authenticatorOnPatch(host, token, data).then(res => {
					console.log('应答邀约状态', res);
					this.$emit('stateChange')
				}).catch(err => {
					console.log('应答邀约状态__失败', err);
					uni.showToast({
						icon: 'error',
						title: '应答失败'
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped></style>